//package com.yanfan.parking.quartz;
//
//import com.alibaba.fastjson2.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.yanfan.common.utils.DateUtils;
//import com.yanfan.common.utils.StringUtils;
//import com.yanfan.ibms.common.utils.HttpUtil;
//import com.yanfan.parking.constant.ParkingConstants;
//import com.yanfan.parking.domain.IbmsParkingFlowHour;
//import com.yanfan.parking.domain.IbmsParkingPlace;
//import com.yanfan.parking.domain.IbmsParkingRecords;
//import com.yanfan.parking.mapper.IbmsParkingPlaceMapper;
//import com.yanfan.parking.mapper.IbmsParkingRecordsMapper;
//import com.yanfan.parking.service.IIbmsParkingFlowHourService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.text.ParseException;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//
///**
// * 定时获取停车场车道信息
// */
//@Component("parkingTask")
//@Slf4j
//public class ParkingTask {
//    @Value("${api.parking.url}")
//    private String url;
//
//    @Resource
//    private IbmsParkingPlaceMapper ibmsParkingPlaceMapper;
//    @Resource
//    private IbmsParkingRecordsMapper ibmsParkingRecordsMapper;
//    @Resource
//    private IIbmsParkingFlowHourService ibmsFlowHourService;
//
////    /**
////     * 获取停车场车道信息数据
////     */
////    public void getParkingLotInfo(){
////
////        HashMap<String, Object> map = new HashMap<>();
////        map.put("stationNo","stationNo");
////        JSONObject jsonObject = HttpUtil.sendPost(url + "/" , null, map);
////        List<IbmsParkingPlace> list = jsonObject.getList(jsonObject.toJSONString("parkingLotInfo"), IbmsParkingPlace.class);
////        //批量更新或新增到数据库
////        ibmsParkingPlaceMapper.insertOrUpdateBatch(list);
////    }
//
//    /**
//     * 车流量每小时统计
//     */
//    public void  flowHour() throws ParseException {
//
//        Date nowDate = DateUtils.getNowDate();
//        //Date time = DateUtils.dateTime("yyyy-MM-dd HH", DateUtils.parseDateToStr("yyyy-MM-dd HH", nowDate));
//        log.info(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", nowDate) + "车流量统计中...");
//
//        // 获取当前时间往前推一小时的时间
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(nowDate);
//        calendar.add(Calendar.HOUR_OF_DAY, -1);
//        Date oneHourAgo = calendar.getTime();
//
//        // 将日期格式化为字符串
//        String nowDateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:00", nowDate);
//        String oneHourAgoStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", oneHourAgo);
//        Date time = DateUtils.dateTime("yyyy-MM-dd HH:00", nowDateStr);
//        // 进场车流量数据
//        List<IbmsParkingRecords> inList = ibmsParkingRecordsMapper.selectList(
//                new LambdaQueryWrapper<IbmsParkingRecords>()
//                        .eq(IbmsParkingRecords::getInOrOut, ParkingConstants.parkingIn)
//                        .between(IbmsParkingRecords::getInTime,oneHourAgo, nowDate )
//        );
//        //出场车流量数据
//        List<IbmsParkingRecords> outList = ibmsParkingRecordsMapper.selectList(new LambdaQueryWrapper<IbmsParkingRecords>()
//                .eq(IbmsParkingRecords::getInOrOut, ParkingConstants.parkingOut)
//                .between(IbmsParkingRecords::getPassTime, oneHourAgo, nowDate));
//
//        IbmsParkingFlowHour ibmsParkingFlowHour = new IbmsParkingFlowHour();
//        //进场流量
//        if (StringUtils.isNotEmpty(inList)){
//            //ibmsParkingFlowHour.setInOut(Long.parseLong(ParkingConstants.parkingIn));//0代表进场
//            ibmsParkingFlowHour.setInOutTime(time);
//            ibmsParkingFlowHour.setInVehicleFlow(inList.size());
//        }else {
//            //ibmsParkingFlowHour.setInOut(Long.parseLong(ParkingConstants.parkingIn));//0代表进场
//            ibmsParkingFlowHour.setInOutTime(time);
//            ibmsParkingFlowHour.setInVehicleFlow(0);
//        }
//        //出场流量
//        if (StringUtils.isNotEmpty(outList)){
//            ibmsParkingFlowHour.setOutVehicleFlow(outList.size());//出场流量
//        }else {
//            ibmsParkingFlowHour.setOutVehicleFlow(0);
//
//        }
//        ibmsFlowHourService.save(ibmsParkingFlowHour);
//    }
//}
